package com.atguigu.gmall.product;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 李旭
 * @date 2022/1/10 15:16
 * @Description:
 *
 * 异步编排
 */
public class CompletableFutureDemo {

    public static void main(String[] args) throws Exception{
        ThreadPoolExecutor threadPoolExecutor =
                 new ThreadPoolExecutor(
                         5,
                         10,
                         5,
                         TimeUnit.SECONDS,
                         new ArrayBlockingQueue<>(10)
                 );

        //1：创建多线程
  /*      CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            return 12434;
        }, threadPoolExecutor);

        System.out.println(integerCompletableFuture.get());*/

 /*       CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
        },threadPoolExecutor);*/

        CompletableFuture<String> stringCompletableFuture =
                CompletableFuture.completedFuture("123456789");
        System.out.println(stringCompletableFuture.get());
    }
}
